/*
 * @version: vue3
 * @Author: lxs
 * @Date: 2022-04-30 09:48:53
 * @LastEditors: sueRimn
 * @LastEditTime: 2022-04-30 13:40:42
 */
import { onMounted, ref } from "vue";
import { image } from "@/api/user/user";
import { ElMessage } from "element-plus";
export default function useImage() {
  // 定义图片的src
  const imgSrc = ref("");

  onMounted(() => {
    getImage();
  });

  // 获取图片
  const getImage = async () => {
    try {
      const res: any = await image();
      imgSrc.value = URL.createObjectURL(res);
    } catch (error) {
      ElMessage.error("获取验证码失败");
    }
  };

  return {
    imgSrc,
    getImage,
  };
}
